#!/bin/bash
set -euo pipefail

component_name="tree"
component_version="2.2.1"
install_prefix="/usr"

export TREE_INSTALL_HNP_PATH="${HNP_PUBLIC_PATH}/${component_name}.org/${component_name}_${component_version}"
echo "Install root: ${TREE_INSTALL_HNP_PATH}"

mkdir -p "${TREE_INSTALL_HNP_PATH}"

make clean
make VERBOSE=1 PREFIX="${install_prefix}" MANDIR="${install_prefix}/share/man"
make install PREFIX="${install_prefix}" DESTDIR="${TREE_INSTALL_HNP_PATH}" MANDIR="${install_prefix}/share/man"

doc_dir="${TREE_INSTALL_HNP_PATH}/usr/share/doc/${component_name}"
mkdir -p "${doc_dir}"
install -m 644 README README.md CHANGES LICENSE INSTALL TODO "${doc_dir}/"

install -m 644 hnp.json "${TREE_INSTALL_HNP_PATH}/"

pushd "${TREE_INSTALL_HNP_PATH}/../"
    ${HNP_TOOL} pack -i "${TREE_INSTALL_HNP_PATH}" -o "${ARCHIVE_PATH}/"
    tar -zvcf "${ARCHIVE_PATH}/ohos_${component_name}_${component_version}.tar.gz" "${component_name}_${component_version}/"
popd
